<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Storage;

class GameList extends Model
{
    const STATUS_CLOSE = 0;
    const STATUS_ENABLED = 1;
    const STATUS_MAINTAIN = 2;

    protected $guarded = [];

    public function gameType()
    {
        return $this->belongsTo(GameType::class, 'type', 'code');
    }

    public function gameLine()
    {
        return $this->belongsTo(GameLine::class, 'line_num', 'code');
    }

    public function gameCategory()
    {
        return $this->belongsTo(GameCategory::class, 'category', 'code');
    }


    public function getImg1Url()
    {
        return $this->img1 ? Storage::url($this->img1) : '';
    }

    public function getImg2Url()
    {
        return $this->img2 ? Storage::url($this->img2) : '';
    }

    public function getStatus()
    {
        switch ($this->status) {
            case self::STATUS_CLOSE:
                return '关闭';
            case self::STATUS_ENABLED:
                return '启用';
            case self::STATUS_MAINTAIN:
                return '维护';
            default:
                return '关闭';
        }
    }

    public function scopeStatus($query)
    {
        return $query->where('status', 1);
    }
}
